import Mock from 'mockjs'

// 模拟数据
export default {
    // 登录接口
    '/api/auth/login post': (options) => {
        const { username, password } = JSON.parse(options.body)
        if (username === 'admin' && password === '123456') {
            return {
                code: 200,
                msg: '登录成功',
                data: {
                    token: Mock.Random.string(32),
                    id: 1,
                    username: 'admin',
                    phone: '13800000000',
                    email: 'admin@example.com',
                    realName: '管理员',
                    avatar: Mock.Random.image('100x100', '#4A7BF7', 'Avatar')
                }
            }
        } else if (username === 'user' && password === '123456') {
            return {
                code: 200,
                msg: '登录成功',
                data: {
                    token: Mock.Random.string(32),
                    id: 2,
                    username: 'user',
                    phone: '13800000001',
                    email: 'user@example.com',
                    realName: '测试用户',
                    avatar: Mock.Random.image('100x100', '#4A7BF7', 'Avatar')
                }
            }
        } else {
            return {
                code: 401,
                msg: '用户名或密码错误',
                data: null
            }
        }
    },

    // 注册接口
    '/api/auth/register post': (options) => {
        const { username, password, phone, email } = JSON.parse(options.body)
        if (username === 'admin') {
            return {
                code: 400,
                msg: '用户名已存在',
                data: null
            }
        } else if (phone === '13800000000') {
            return {
                code: 400,
                msg: '手机号已存在',
                data: null
            }
        } else {
            return {
                code: 200,
                msg: '注册成功',
                data: {
                    id: Mock.Random.integer(3, 100),
                    username,
                    phone,
                    email
                }
            }
        }
    },

    // 获取用户信息接口
    '/api/users/\\d+ get': (options) => {
        return {
            code: 200,
            msg: '获取成功',
            data: {
                id: 1,
                username: 'admin',
                phone: '13800000000',
                email: 'admin@example.com',
                realName: '管理员',
                idCard: '110101199001010000',
                avatar: Mock.Random.image('100x100', '#4A7BF7', 'Avatar'),
                status: 1,
                lastLoginTime: Mock.Random.datetime(),
                lastLoginIp: Mock.Random.ip(),
                createTime: Mock.Random.datetime(),
                updateTime: Mock.Random.datetime(),
                gender: 1,
                age: 30,
                birthday: '1990-01-01 00:00:00',
                maritalStatus: 1,
                education: 5,
                occupation: '软件工程师',
                companyName: '科技有限公司',
                companyAddress: '北京市海淀区中关村',
                companyPhone: '010-12345678',
                monthlyIncome: 1000000,
                address: '北京市朝阳区',
                emergencyContactName: '张三',
                emergencyContactPhone: '13900000000',
                emergencyContactRelation: 0
            }
        }
    },

    // 更新用户信息接口
    '/api/users put': () => {
        return {
            code: 200,
            msg: '更新成功',
            data: null
        }
    },

    // 修改密码接口
    '/api/users/password put': () => {
        return {
            code: 200,
            msg: '修改成功',
            data: null
        }
    }
}